//
//  EveryDaySignView.swift
//  TianTianBiTing
//
//  Created by Gox mac 2 on 2019/3/1.
//  Copyright © 2019 Gox_WallyDiao. All rights reserved.
//

import UIKit

class EveryDaySignView: UIView {
    var checkBlock:(() -> Void)?
    var signBlock:(() -> Void)?
    var closeBlock:(() -> Void)?
    lazy var checkBtn:UIButton = {
        let button = UIButton(type: UIButton.ButtonType.custom)
        button.frame = FRAME_CGFloat(SCREEN_WIDTH / 2 - 30, 492, 60, 18.5)
        button.setTitle("查看详情", for: .normal)
        button.setTitleColor(.white, for: .normal)
        button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 13)
        button.addTarget(self, action: #selector(checkAction), for: .touchUpInside)
        return button
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.clear
        setUI()
    
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUI() {
        self.backgroundColor = RGB_Same(0, 0.8)
        
        let backImageView = UIImageView.init(frame: FRAME_CGFloat(SCREEN_WIDTH / 2 - 170, 60.5, 340, 324))
        self.addSubview(backImageView)
        backImageView.isUserInteractionEnabled = true
        backImageView.image = IMAGE(name: "signRed_bg")
        
        let centreView = SignDayView.init(frame: FRAME_CGFloat(SCREEN_WIDTH / 2 - 115, 374, 230, 20))
        self.addSubview(centreView)
        
        let signImageView = UIImageView.init(frame: FRAME_CGFloat(SCREEN_WIDTH / 2 - 137.3, 430, 275, 45))
        self.addSubview(signImageView)
        signImageView.isUserInteractionEnabled = true
        signImageView.image = IMAGE(name: "signRed_签到按钮")
        signImageView.addGestureRecognizer(UITapGestureRecognizer(target:self, action:#selector(signAction)))
        
        self.addSubview(self.checkBtn)
  
        let button = UIButton(type: UIButton.ButtonType.custom)
        button.frame = FRAME_CGFloat(SCREEN_WIDTH / 2 - 9, 548, 17.5, 17.5)
        button.setImage(IMAGE(name: "signRed_close"), for: .normal)
        button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 19)
        button.addTarget(self, action: #selector(closeBtnAction), for: .touchUpInside)
        self.addSubview(button)
        
    }
    
    @objc func signAction() {
        WelfareRequestModel.loadSignInRecordData { (success) in
            if success {
                self.isHidden = true
                self.removeFromSuperview()
                self.signBlock?()
            } else {
                self.isHidden = false
            }
        }
        
    }
    
    @objc func closeBtnAction() {
        self.isHidden = true
        self.removeFromSuperview()
    }
    
    @objc func checkAction() {
        self.isHidden = true
        self.removeFromSuperview()
        checkBlock?()
        
    }

}
